package com.zaizai.controller;

import java.util.List;


import com.zaizai.aop.AutoLog;
import com.zaizai.domain.AjaxResult;
import com.zaizai.domain.Type;
import com.zaizai.service.ITypeService;
import com.zaizai.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.zaizai.domain.AjaxResult.success;


/**
 * 分类Controller
 *
 * @author zaiZai
 * @date 2024-10-21
 */

@RestController
@RequestMapping("/type")
public class TypeController extends BaseController {
    @Autowired
    private ITypeService typeService;

/**
 * 查询分类列表
 */

@GetMapping("/list")
    public TableDataInfo list(Type type) {
        startPage();
        List<Type> list = typeService.selectTypeList(type);
        return getDataTable(list);
    }

    /**
     * 获取分类详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(typeService.selectTypeById(id));
    }

    /**
     * 新增分类
     */
    @PostMapping
    @AutoLog("新增分类信息")
    public AjaxResult add(@RequestBody Type type) {
        return success(typeService.insertType(type));
    }

    /**
     * 修改分类
     */

    @PutMapping
    @AutoLog("修改分类信息")
    public AjaxResult edit(@RequestBody Type type) {
        return success(typeService.updateType(type));
    }

    /**
     * 删除分类
     */

    @DeleteMapping("/{ids}")
    @AutoLog("删除分类信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(typeService.deleteTypeByIds(ids));
    }
}
